package com.example.lottery.dao.mapper;

import com.example.lottery.dao.datobject.ActivityDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    @Insert("insert into activity (activity_name, description, status)" +
            " values (#{activityName}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty ="id", keyColumn ="id")
//    主要用于在插入数据后，自动将数据库生成的主键值回填到实体对象中
    //因为返回的是活动id，所以开启这个功能
    void insert(ActivityDO activityDO);

   @Select("select * from activity where id=#{activityId}")
    ActivityDO selectById(@Param("activityId") Long activityId);

   @Select("select count(*) from activity")
    int count();

   @Select("select * from activity order by id desc limit #{offset},#{pageSize}")
    List<ActivityDO> selectActivityList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

   @Update("update activity set status=#{status} where id=#{activityId}")
    void updateStatus(@Param("activityId")Long activityId, @Param("status")String status);
}
